home *** CD-ROM | disk | FTP | other *** search
- /* AEvent.c */
-
- #include <Types.h>
- #include <Quickdraw.h>
- #include <Controls.h>
- #include <Dialogs.h>
- #include <Events.h>
- #include <Files.h>
- /*#include <Lists.h>*/
- #include <Menus.h>
- #include <TextEdit.h>
- #include <AppleEvents.h>
-
- #ifndef __GLO__
- #include "Globals.h"
- #endif
- #ifndef __RED__
- #include "ResourceDefs.h"
- #endif
- #ifndef __MIS__
- #include "Miscellany.h"
- #endif
- #ifndef __FIM__
- #include "FileM.h"
- #endif
- #ifndef __AEV__
- #include "AEvent.h"
- #endif
- #define jcu TRUE
-
- /*void AEvent_seg() {}*/
-
- #pragma segment AEvent
-
-
-
- /*----------*/
- void InitializeAE () /* C14 */
- {
- OSErr errCode;
-
- /* /* install the required apple event handlers »*/
- /* AEEventHandlerUPP OPENae, QUITae, STARTae, PRINTae;*/
- /**/
- /* /* must use these for PPC proc pointers »*/
- /* OPENae = NewAEEventHandlerProc ((ProcPtr) &openAE);*/
- /* QUITae = NewAEEventHandlerProc ((ProcPtr) &quitAE);*/
- /* STARTae = NewAEEventHandlerProc ((ProcPtr) &startAE);*/
- /* PRINTae = NewAEEventHandlerProc ((ProcPtr) &printAE);*/
- /**/
- /* err = AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments,*/
- /* OPENae, 0, FALSE);*/
- /* if (err) died ("Error Installing OpenDoc Apple Event", err, 9);*/
- /* */
- /* err = AEInstallEventHandler (kCoreEventClass, kAEQuitApplication,*/
- /* QUITae, 0, FALSE);*/
- /* if (err) died ("Error Installing QuitApp Apple Event", err, 10);*/
- /* */
- /* err = AEInstallEventHandler (kCoreEventClass, kAEOpenApplication,*/
- /* STARTae, 0, FALSE);*/
- /* if (err) died ("Error Installing OpenApp Apple Event", err, 11);*/
- /* */
- /* err = AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments,*/
- /* PRINTae, 0, FALSE);*/
- /* if (err) died ("Error Installing PrintDoc Apple Event", err, 12);*/
-
-
-
- errCode = AEInstallEventHandler (kCoreEventClass, kAEOpenApplication, NewAEEventHandlerProc(DoAEOpenApp), 0L, false);
- errCode = AEInstallEventHandler (kCoreEventClass, kAEOpenDocuments, NewAEEventHandlerProc(DoAEOpenDoc), 0L, false);
- errCode = AEInstallEventHandler (kCoreEventClass, kAEPrintDocuments, NewAEEventHandlerProc(DoAEPrintDoc), 0L, false);
- errCode = AEInstallEventHandler (kCoreEventClass, kAEQuitApplication, NewAEEventHandlerProc(DoAEQuit), 0L, false);
-
- } /*InitializeAE*/
-
- /*----------*/
-
-
- #ifdef jcu
- void DoHighLevelEvent (EventRecord *theEvent)
- #else
- void DoHighLevelEvent (void)
- #endif
- {
- OSErr errCode;
-
- /* check to see if the Apple event is of a user-defined class; */
- /* if so, handle it. Otherwise, call AEProcessAppleEvent. */
-
- #ifdef jcu
- errCode = AEProcessAppleEvent (theEvent);
- #else
- errCode = AEProcessAppleEvent (&curEvent);
- #endif
- if (errCode == errAEEventNotHandled) {
- /*?? Acknowledge (CantHandleAEVTID); ??*/
- }
-
- } /*DoHighLevelEvent*/
-
- /*----------*/
- /* This routine checks to verify that the caller has processed */
- /* all of the event's parameters. If no parameters are found */
- /* then it returns noErr. */
- /*----------*/
- OSErr MyGotRequiredParams (const AppleEvent *theEvent)
- {
- OSErr errCode;
- Size actualSize;
- DescType returnedType;
-
- errCode = AEGetAttributePtr (theEvent, keyMissedKeywordAttr, typeWildCard,
- &returnedType, NULL, 0, &actualSize);
-
- if (errCode == errAEDescNotFound) { /*no parameters => no error*/
- errCode = noErr;
- } else if (errCode == noErr) { /*got a parameter => it wasn't handled*/
- errCode = errAEEventNotHandled;
- } /*AEGetAttributePtr failed*/
-
- return (errCode);
- } /*MyGotRequiredParams*/
-
- /*----------*/
- pascal OSErr DoAEOpenApp (AppleEvent *theEvent,
- AppleEvent *reply,
- long refCon)
- {
- #pragma unused (reply)
- #pragma unused (refCon)
-
- OSErr errCode;
-
- errCode = MyGotRequiredParams (theEvent);
- if (errCode == noErr) {
- OpenApp ();
- }
-
- return (errCode);
- } /*DoAEOpenApp*/
-
- #if !defined(applec) /* MPW C */ && !defined(THINK_C) /* AUX */
- /*----------*/
- /* Need to use PBOpenWD here instead of OpenWD because of an AUX 3.0 bug which omitted */
- /* the glue for OpenWD, resulting in a link error if OpenWD is used. */
- /*----------*/
- static OSErr AUXOpenWD (short vRefNum,
- long dirID,
- long procID,
- short *wdRefNum)
- {
- WDPBRec wdOpenRec;
- OSErr errCode;
- short i;
- Ptr p;
-
- /* Need to use a local WDPBRec here and clear it out ourselves (instead of using a WDPBPtr */
- /* and NewPtrClear) because of an AUX 3.0 bug which omitted the glue for NewPtrClear, */
- /* resulting in a link error if NewPtrClear is used. */
- for (i = 0, p = (Ptr) &wdOpenRec; i < sizeof (WDPBRec); i++, p++) {
- *p = 0; /* clear out wdOpenRec */
- }
- wdOpenRec.ioVRefNum = vRefNum;
- wdOpenRec.ioWDProcID = procID;
- wdOpenRec.ioWDDirID = dirID;
- errCode = PBOpenWD (&wdOpenRec, false);
- if (errCode == noErr) {
- *wdRefNum = wdOpenRec.ioVRefNum;
- }
-
- return (errCode);
- } /*AUXOpenWD*/
- #endif /* AUX */
-
- /*----------*/
- pascal OSErr DoAEOpenDoc (AppleEvent *theEvent,
- AppleEvent *reply,
- long refCon)
- {
- #pragma unused (reply)
- #pragma unused (refCon)
-
- OSErr errCode;
- OSErr ignoreErr;
- AEDescList docList;
- long itemsInList;
- long index;
- AEKeyword keyword;
- DescType returnedType;
- Size actualSize;
- FSSpec myFSS;
- short wdRefNum;
-
- errCode = AEGetParamDesc (theEvent, keyDirectObject, typeAEList, &docList);
- if (errCode == noErr) {
- errCode = MyGotRequiredParams (theEvent);
- if (errCode == noErr) {
- errCode = AECountItems (&docList, &itemsInList);
- if (errCode == noErr) {
- for (index = 1; index <= itemsInList; index++) {
- errCode = AEGetNthPtr (&docList, index, typeFSS, &keyword,
- &returnedType, (Ptr) &myFSS, sizeof (myFSS), &actualSize);
- if (errCode == noErr) {
- #if defined(applec) /* MPW C */ || defined(THINK_C)
- errCode = OpenWD (myFSS.vRefNum, myFSS.parID, 0L /* procID */, &wdRefNum);
- #else /* AUX */
- errCode = AUXOpenWD (myFSS.vRefNum, myFSS.parID, 0L /* procID */, &wdRefNum);
- #endif
- if (errCode == noErr) {
- OpenDoc (myFSS.name, wdRefNum);
- }
- }
- } /*for*/
- }
- }
- ignoreErr = AEDisposeDesc (&docList);
- }
-
- return (errCode);
- } /*DoAEOpenDoc*/
-
- /*----------*/
- pascal OSErr DoAEPrintDoc (AppleEvent *theEvent,
- AppleEvent *reply,
- long refCon)
- {
- #pragma unused (reply)
- #pragma unused (refCon)
-
- OSErr errCode;
-
- errCode = MyGotRequiredParams (theEvent);
- if (errCode == noErr) {
- /*?? Acknowledge (CantPrintID); ??*/ ;
- }
-
- return (errCode);
- } /*DoAEPrintDoc*/
-
- /*----------*/
- pascal OSErr DoAEQuit (AppleEvent *theEvent,
- AppleEvent *reply,
- long refCon)
- {
- #pragma unused (reply)
- #pragma unused (refCon)
-
- OSErr errCode;
-
- errCode = MyGotRequiredParams (theEvent);
- if (errCode == noErr) {
- DoQuit ();
- }
-
- return (errCode);
- } /*DoAEQuit*/
-
- /*----------*/
- /* Add an InteractWithUser as an example of how it is done.*/
- /* Include an IdleProc which updates windows in the background.*/
-
- /*AEvent*/
-